<?php
namespace src\lib;

use src\Curl;

/**
 * 今日头条图床
 * Class Toutiao
 * @package src\lib
 * @url https://mp.toutiao.com/
 */

class Toutiao
{
    public function upload($path)
    {
        $data = [
            'photo' => Curl::getCurlFile($path),
        ];
        $result = Curl::post('https://mp.toutiao.com/upload_photo/?type=json', $data, [
            CURLOPT_HTTPHEADER => [
                'Origin: https://mp.toutiao.com',
                'Referer: https://mp.toutiao.com/profile_register_v3/register/register-normal/2'
            ],
        ]);

        $json = json_decode($result, true);
        if(isset($json['message']) && $json['message'] == 'success' && isset($json['web_url'])){
            return $json['web_url'];
        }

        return false;
    }

}